package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.Token;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// QGainPitch
/**
@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class QGainPitch extends TypedAtomicActor {

    public QGainPitch(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        gain = new TypedIOPort(this, "gain", true, false);
        gain.setTypeEquals(BaseType.OBJECT);

        index = new TypedIOPort(this, "index", false, true);
        index.setTypeEquals(BaseType.OBJECT);

        gain_out = new TypedIOPort(this, "gain_out", false, true);
        gain_out.setTypeEquals(BaseType.OBJECT);

        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort gain;
    public TypedIOPort txdtx_ctrl;

    // Output Ports
    public TypedIOPort index;
    public TypedIOPort gain_out;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short txdtx = (Short) obj.getValue();
        if((txdtx.shortValue() & Cnst.TX_SP_FLAG) != 0) {
            obj = (ObjectToken) gain.get(0);
            Short arg1 = (Short) obj.getValue();

            _q_gain_pitch(arg1);

            index.broadcast(new ObjectToken(_index));
            gain_out.broadcast(new ObjectToken(_gain));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private void _q_gain_pitch(Short gain) {

    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private Short _gain;
    private Short _index;
}
